<?php

namespace App\Kuafu\CustomerCoupon\Enum;

use App\Kuafu\Base\Enum\BaseCodeEnum;

class CustomerCouponCacheEnum extends BaseCodeEnum
{

    /**
     * 绑定手机号送券活动过期时间
     */
    public const BAND_ACTIVITY_INFO_TIME = 360;

    private const BAND_MOBILE_ACTIVITY_INFO = 'band-mobile-activity';

    /**
     * 用户领券锁
     */
    private const REGISTER_SEND_COUPON_LOCK = 'register_send_coupon_lock:userId:%d';

    private const ACTIVITY_RECEIVE_COUPON_LOCK = 'register_send_coupon_lock:activityId:%d:userId:%d';

    private const CUSTOMER_COUPON_USED_STATUS = 'customer_coupon_used_status_id:%d';


    public static function getBandMobileActivityInfo(int $activityId): string
    {
        return sprintf(self::BAND_MOBILE_ACTIVITY_INFO . ":%d", $activityId);
    }

    /**
     * 获取发放优惠券用户锁
     * @param int $userId
     * @param $shopId
     * @return string
     */
    public static function getSendCouponLock(int $userId): string
    {
        return sprintf(self::REGISTER_SEND_COUPON_LOCK, $userId);
    }

    /**
     * 获取活动领券缓存锁
     *
     * @param int $userId
     * @param int $activityId
     * @return string
     */
    public static function getActivityReceiveCouponLock(int $userId, int $activityId): string
    {
        return vsprintf(self::ACTIVITY_RECEIVE_COUPON_LOCK, [$activityId, $userId]);
    }

    public static function getUserCouponStatusKey(int $customerCouponId)
    {
        return vsprintf(self::CUSTOMER_COUPON_USED_STATUS, [$customerCouponId]);
    }
}
